package com.deam.imsdk.elem;

import com.alibaba.fastjson.JSONObject;
import com.deam.imsdk.utils.Constants;
import com.deam.imsdk.utils.MathUtil;

/**
 * 文本消息
 */
public class IMTextElem extends BaseElem {


    public IMTextElem() {
        setType(ElemType.TEXT);
    }

    public IMTextElem(JSONObject jsonData) {
        if (jsonData == null) return;
        setType(ElemType.TEXT);
        setAcceptorId(jsonData.getString(Constants.EL_ACCEPTOR_ID));
        setSenderId(jsonData.getString(Constants.EL_SENDER_ID));
        setContext(jsonData.getString(Constants.EL_CONTEXT));
        setTime(jsonData.getLongValue(Constants.EL_TIME));
        setIdentifying(jsonData.getString(Constants.EL_IDENTIFYING));
    }

    @Override
    public String toMessageString() {
        JSONObject json = new JSONObject();
        json.put(Constants.EL_ACCEPTOR_ID, getAcceptorId());
        json.put(Constants.EL_CONTEXT, getContext());
        json.put(Constants.EL_IDENTIFYING, getIdentifying());
        json.put(Constants.REQUEST, Constants.ACTION_TYPE_TEXT);
        json.put(Constants.USER_ACTION, Constants.ACTION_TYPE_TEXT);
        json.put(Constants.EL_TYPE, getType().name());
        return json.toJSONString();
    }
}
